home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: "A. Sander" <pa101aa@sunmail.lrz-muenchen.de>
- Newsgroups: comp.lang.c++
- Subject: Re: Virtual Inheritance
- Date: Mon, 08 Apr 1996 10:43:05 +0200
- Organization: none
- Distribution: world
- Message-ID: <3168D199.7470@sunmail.lrz-muenchen.de>
- References: <4k9tpv$173k@news-s01.ny.us.ibm.net>
- NNTP-Posting-Host: dial037.ppp.lrz-muenchen.de
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (WinNT; I)
-
- bbogard@ibm.net wrote:
- >
- > I was recently talking to a possible employer on the phone, and he asked me a question
- > about C++ I had never heard of before. He has me what is virtual inheritance? Is this
- > an ANSI compatible extension or something. I have used a number of compilers including
-
- it's (or say, will be) ANSI.
-
- > VC 4.1 and BC 4.5 and neither of those had virtual inheritance defined in the language.
-
- wrong, they have.
-
- > What is it, and what is it used for?
-
- My (negative) opinion about virtual inhertance follows:
-
- Well, virtual inheritance is only ... wah! only a workaround
- for a common problem occuring using multiple inheritance.
-
- If you use multiple inheritance in following example:
-
- class base
- {};
- class a : public base
- {};
- class b : public base
- {}
- class c : public a, public b
- {};
-
- you will get:
-
- base base
- \ /
- a b
- \/
- c
-
- and here starts the problem, that in most cases you don't need
- that duplicated base-class. With virtual inheritance:
-
- class base
- {};
- class a : virtual public base
- {};
- class b : virtual public base
- {}
- class c : public a, public b
- {};
-
- you get the expected result:
-
- base
- /\
- a b
- \/
- c
-
-
- I personally have tried to use virtual inheritance in several
- ways. But in fact I was never successful building class hierarchies
- using multiple/virtual inheritance.
-
- ciao,
- Armin
-